﻿using System;
using System.Diagnostics;
using ProjectDeployment.Loggers;

namespace ProjectDeployment.Model
{
    class MsiInstall : IInstallBehavior
    {
        private Logger _logger = Logger.instance;
        public void Install(string installerPath)
        {
            Install(installerPath, string.Empty);
        }

        public void Install(string installerPath, string parameters)
        {
            try
            {
                var startinfo = new ProcessStartInfo
                            (
                                "msiexec.exe",
                                string.Format("/i \"{0}\" /qb {1}", installerPath, parameters)
                            );
                var projectProcess = Process.Start(startinfo);
                projectProcess.WaitForExit();
            }
            catch (Exception ex)
            {
                _logger.AddLogMessage("There was an error installing the MSI file: " + ex);
            }
        }
    }
}
